package com.atguigu.singleton.type5;

public class SingleTonTest04 {
    public static void main(String[] args) {
        SingleTon instance = SingleTon.getInstance();
        System.out.println(SingleTon.getInstance() == instance);
    }
}

class SingleTon {
    private static SingleTon instance;

    private SingleTon() {

    }

    /**
     * 懒汉式,给创建单例对象的new 加同步,其实这样根本没用
     *
     * @return 单例
     */
    public static SingleTon getInstance() {
        if (instance == null) {
            synchronized (SingleTon.class) {
                instance = new SingleTon();
            }
        }
        return instance;
    }
}
